export default {
  bind(el, binding, vnode){
    //响应点击后滚动到元素顶部
    el.addEventLister("click", ()=>{
      const target = binding.arg ? document.getElementById(binding.arg) : window 
      target.screenTop({
        top:0,
        behavior:'smooth'
      })
    })
  },

  update(el, binding, vnode){
   //滚动到达参数值才出现绑定指令的元素
   const target = binding.arg ? document.getElementById(binding.arg) : window
   if(binding.value){
     target.addEventListener("scroll", (e)=>{
       if(e.scrollTop > binding.value){
         el.style.visibility = 'unset'
       }else {
         el.style.visibility = 'hidden'
       }
     })
   }
   //判断初始化状态
   if(target.screenTop < binding.value){
     el.style.visibility = 'hidden'
   }
  },

  unbind(el, binding, vnode){
    const target = binding.arg ? document.getElementById(binding.arg) : window
    target.removeEventListener('scroll')
    el.removeEventListener('click')
  }

}